/** @file AvatarPhysicsComponent.h
    @class AvatarPhysicsComponent
    @brief Class that describes the physics component for the player's game avatar

    The physics component that represents the  player's game avatar as a capsule.
*/
#include "stdafx.h"

#pragma once

#ifndef _AvatarPhysicsComponent_h_
#define _AvatarPhysicsComponent_h_

#include "PhysicsComponent.h"
#include <Physics\Utilities\CharacterControl\FirstPersonCharacter\hkpFirstPersonCharacter.h>
#include <Physics\Utilities\CharacterControl\StateMachine\hkpCharacterContext.h>
class AvatarPhysicsComponent : public PhysicsComponent {
public:
	/**
	 *	@brief Constructor
	 *	@param position The start position of the avatar physics component
	 */
	AvatarPhysicsComponent(Ogre::Vector3 position);

	/**
	 *	@brief Destructor
	 */
	~AvatarPhysicsComponent();

	/**
	 *	@brief Changes the turning angle for the next update, where the character will turn.
	 *	@param angle Angle of turn
	 */
	void turn(float angle);

	/**
	 *	@brief Updates the character according to user input.
	 *	@param timestep	Time since last update
	 *	@param posX Position in x-axis
	 *	@param posY	Position in y-axis
	 *	@param wantJump	If the player wants to jump
	 */
	void updateCharacter(float timestep, float posX, float posY, bool wantJump);
	
private:
	/**
	 *	@brief Turns the character
	 *	@param rotation	Angle of turn
	 *  @param timestep	Number of seconds since last reorientation
	 */
	bool reorientCharacter(const hkRotation& rotation, hkReal timestep);

	/**
	 *	@brief Havok character-specialized rigid body
	 */
	hkpCharacterRigidBody* m_char;

	/**
	 *	@brief Havok context for the character
	 */
	hkpCharacterContext* m_charContext;

	/**
	 *	@brief State manager for the character
	 */
	hkpCharacterStateManager* m_manager;

	/**
	 *	@brief Ground from previous frame
	 */
	hkpSurfaceInfo* m_previousGround;

	/**
	 *	@brief Current orientation of character
	 */
	hkQuaternion m_currentOrient;

	/**
	 *	@brief Time since created
	 */
	float m_time;

	/**
	 *	@brief Current angle of character
	 */
	float m_currentAngle;

	/**
	 *	@brief Number of frames that the character spent in the air
	 */
	int m_framesInAir;
};

#endif